use std::ffi::CStr;

pub const IM_SQL: &CStr = c"
create table im_department
(
    id             INTEGER   NOT NULL primary key AUTOINCREMENT,
    currentUserId  varchar(20) not null,
    name           varchar(126) not null,
    code           varchar(24) not null,
    parentCode     varchar(24) null,
    description    varchar(2048) null,
    status         INTEGER not null,
    managerUserId  varchar(20) null,
    otherManagerUserIds varchar(2048) null,
    ext1            varchar(2048) null,
    ext2            varchar(2048) null,
    createTime      varchar(23)  NOT NULL,
    updateTime      varchar(23) not null
);
create UNIQUE index udx_code on im_department(code);


create table im_session
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    name            varchar(126) not null,
    serverId        varchar(20),
    currentUserId   varchar(20)  not null,
    fromUserId      varchar(20),
    toUserId        varchar(20),
    groupCode       varchar(64),
    sessionType     INTEGER,
    hotMessageTotal integer      not null default 0,
    latelyMessage   varchar(256),
    status          INTEGER,
    isWaking        boolean,
    isTop           boolean,
    isDisturb       boolean,
    isWaking2       boolean,
    isTop2          boolean,
    isDisturb2      boolean,
    ext1            varchar(2048),
    ext2            varchar(2048),
    createTime      varchar(23)     NOT NULL,
    updateTime      varchar(23)     not null
);
create unique index udx_session_p2p on im_session(currentUserId, fromUserId, toUserId);
create unique index udx_session_p2g on im_session(currentUserId, groupCode);
create index idx_session_updateTime on im_session(updateTime);
create index idx_session_serverId on im_session(serverId);


create table im_group
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    currentUserId   varchar(20)  not null,
    code            varchar(64) NOT NULL,
    serverId        varchar(64),
    name            varchar(128) NOT NULL,
    userId          varchar(20),
    ownerId         varchar(20),
    description     varchar(1024),
    groupType       INTEGER,
    version         INTEGER       not null default 0,
    status          INTEGER,
    ext1            varchar(2048),
    ext2            varchar(2048),
    firstLetter     varchar(1),
    createTime      varchar(23)     NOT NULL,
    updateTime      varchar(23)     not null
);
create index im_group_userId on im_group (currentUserId, userId);
create unique index im_group_code on im_group (currentUserId, code);
create index im_group_updateTime on im_group (updateTime);



create table im_group_user
(
    id         INTEGER   NOT NULL primary key AUTOINCREMENT,
    userId     varchar(20) not null,
    userName   varchar(64),
    groupId    INTEGER   not null,
    remark     varchar(64),
    isWaking   boolean,
    status     INTEGER,
    isShowName boolean,
    isTop      boolean,
    isDisturb  boolean,
    ext1       varchar(2048),
    ext2       varchar(2048),
    createTime varchar(20)  NOT NULL,
    updateTime varchar(20) not null
);
create unique index im_group_user_group_id on im_group_user (groupId, userId);


create table im_user
(
    id           INTEGER      NOT NULL primary key AUTOINCREMENT,
    userId       varchar(20) not null,
    userName     varchar(64),
    mobile       varchar(18),
    motto        varchar(256),
    description  varchar(256),
    headImg      varchar(128),
    status       INTEGER not null,
    sex          INTEGER,
    departmentCode varchar(20),
    otherDepartmentCodes varchar(1024),
    ext1         varchar(2048),
    ext2         varchar(2048),
    firstLetter  varchar(1),
    createTime   varchar(20)     NOT NULL,
    updateTime   varchar(20)    not null
);
create UNIQUE index udx_user_userId on im_user(userId);
create index idx_user_departmentCode on im_user(departmentCode);


create table im_message
(
    id          INTEGER        NOT NULL primary key AUTOINCREMENT,
    clientId    varchar(64),
    fromUserId  varchar(20),
    toUserId    varchar(20),
    currentUserId   varchar(20)  not null,
    serverId    varchar(64),
    messageType varchar(64)       NOT NULL,
    content     varchar(4096)     not null,
    groupCode   varchar(64),
    sessionId   integer,
    refType     INTEGER,
    refMessageIds varchar(1024),
    version     INTEGER            not null default 0,
    ext         varchar(2048),
    ext1        varchar(2048),
    ext2        varchar(2048),
    status      INTEGER      not null,
    fileStatus  INTEGER,
    actionStatus INTEGER,
    serverReceiveTime  varchar(23),
    createTime  varchar(20)      NOT NULL,
    updateTime  varchar(20)     not null
);
create index idx_message_sessionId on im_message (currentUserId, sessionId, serverReceiveTime);
create index idx_message_user_id on im_message (currentUserId, fromUserId);
create index idx_message_server_receive_time on im_message (currentUserId, serverReceiveTime);
create UNIQUE index udx_message_cuid_clientId on im_message(currentUserId, clientId);
create UNIQUE index udx_message_cuid_serverId on im_message(currentUserId, serverId);


create table im_message_send
(
    id           INTEGER        NOT NULL primary key AUTOINCREMENT,
    messageId    INTEGER NOT NULL,
    userId       varchar(20) NOT NULL,
    status       INTEGER NOT NULL,
    fileStatus   INTEGER,
    actionStatus INTEGER,
    createTime   varchar(20) not null,
    updateTime   varchar(20) NOT NULL
);
create UNIQUE index udx_im_message_send_mid_uid on im_message_send (messageId, userId);


create table im_setting
(
    id         INTEGER      NOT NULL primary key AUTOINCREMENT,
    name       varchar(28)  not null,
    currentUserId   varchar(20)  not null,
    description varchar(256),
    value      varchar(256) not null,
    ext1       varchar(2048),
    ext2       varchar(2048),
    createTime varchar(20)    NOT NULL,
    updateTime varchar(20)    not null,
    unique (currentUserId, name)
);

create table im_cache_login_user
(
    id           INTEGER      NOT NULL primary key AUTOINCREMENT,
    userId       varchar(20)  not null,
    loginType    INTEGER NOT  NULL,
    token        varchar(256) not null,
    maskPassword varchar(20)  not null,
    updateTime   varchar(20)  not null
);
create UNIQUE index udx_clu_userId on im_cache_login_user(userId);

create table im_sensitive_word
(
    id           INTEGER      NOT NULL primary key AUTOINCREMENT,
    word         varchar(156)  not null,
    status       INTEGER not null,
    createTime   varchar(20)    NOT NULL,
    updateTime   varchar(20)    not null
);
create unique index udx_im_sw_word on im_sensitive_word(word);

create table im_module
(
    id                  INTEGER       NOT NULL primary key AUTOINCREMENT,
    name                varchar(126)  not null,
    description         varchar(1024),
    no                  INTEGER,
    status              INTEGER       not null,
    createTime          varchar(20)   NOT NULL,
    updateTime          varchar(20)   not null
);
create unique index module_name on im_module(name);

create table im_module_item
(
    id                  INTEGER        NOT NULL primary key AUTOINCREMENT,
    moduleId            INTEGER        not null,
    name                varchar(64)    not null,
    description         varchar(126),
    icon                varchar(256),
    type                INTEGER       not null,
    url                 varchar(256) ,
    params              varchar(256),
    no                  INTEGER,
    status              INTEGER       not null,
    createTime          varchar(20)   NOT NULL,
    updateTime          varchar(20)   not null
);
create unique index module_item_moduleId_name on im_module_item(moduleId, name);










create table im_collect
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    serverId        varchar(20),
    userId          varchar(20)  not null,
    sessionId       varchar(20)  not null,
    messageId       varchar(20)  not null,
    content         clob,
    messageType     varchar(64),
    labelIds        varchar(1024),
    status          INTEGER         not null,
    createTime      varchar(23)     NOT NULL,
    updateTime      varchar(23)     not null
);
create UNIQUE index udx_im_collect_uid_sid_mid on im_collect (userId, sessionId, messageId);
create UNIQUE index udx_im_collect_uid_serverId on im_collect (userId, serverId);
create index im_collect_label_ids on im_collect(labelIds);
create index im_collect_update_time on im_collect(updateTime);



create table im_label
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    serverId        varchar(20),
    currentUserId   varchar(20)  not null,
    name            varchar(156) not null,
    status          INTEGER      not null,
    createTime      varchar(23)     NOT NULL,
    updateTime      varchar(23)     not null
);
create UNIQUE index udx_im_label_cuid_name on im_label (currentUserId, name);
create UNIQUE index udx_im_label_cuid_serverId on im_label (currentUserId, serverId);
create index im_label_update_time on im_collect(updateTime);


create table im_file
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    currentUserId   varchar(20)  not null,
    sessionId       varchar(20)  not null,
    messageId       varchar(20)  not null,
    fileName        varchar(256) not null,
    md5             varchar(126) not null,
    fileSize        INTEGER      not null,
    path            varchar(1024)not null,
    isRelativePath  varchar(20)  not null,
    suffix          varchar(64)  not null,
    status          INTEGER      not null,
    createTime      varchar(23)  NOT NULL,
    updateTime      varchar(23)  not null
);
create unique index udx_im_file_cuid_sid_mid on im_file (currentUserId, sessionId, messageId);
create unique index udx_im_file_cuid_md5 on im_file (currentUserId, md5);
create index idx_im_file_update_time on im_file(createTime);
create index idx_im_file_suffix on im_file(suffix);

create table im_config
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    currentUserId   varchar(20)  not null,
    name            varchar(56)  not null,
    content         varchar(1024)not null,
    status          INTEGER      not null,
    createTime      varchar(23)  NOT NULL,
    updateTime      varchar(23)  not null
);
create unique index idx_im_config_cuid_name on im_config(currentUserId, name);


create table im_feedback
(
    id              INTEGER      NOT NULL primary key AUTOINCREMENT,
    currentUserId   varchar(20)  not null,
    serverId        varchar(20)  not null,
    title           varchar(256) not null,
    content         varchar(1024)not null,
    result          varchar(1024),
    status          INTEGER      not null,
    createTime      varchar(23)  NOT NULL,
    updateTime      varchar(23)  not null
);
create index idx_im_feedback_cuid_title on im_feedback(currentUserId, title);
";